#include <iostream>
#include <cmath>
using namespace std;


bool lineline_intersection(double x1, double y1, double x2, double y2,
						   double x3, double y3, double x4, double y4,
						   double& x, double& y)
{
	const double epsinon=1e-9;
	double u_base=(y4-y3)*(x2-x1)-(x4-x3)*(y2-y1);
	if(fabs(u_base)<epsinon)
		return false;

	double ua=(x4-x3)*(y1-y3)-(y4-y3)*(x1-x3);
	double ub=(x2-x1)*(y1-y3)-(y2-y1)*(x1-x3);
	ua/=u_base;
	ub/=u_base;
	x=x1+ua*(x2-x1);
	y=y1+ub*(y2-y1);
	return true;
}

int main()
{
	double x,y;
	cout<< lineline_intersection(0,0,0,1,1, 0, 1,1, x,y) <<endl; // 0
	cout<< lineline_intersection(0,0,1,1,		0,1,1,0,x,y)<<endl; // 1
	cout<< x <<"," <<y<<endl; // 0.5,0.5
}